home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <types.h>
- #include <stat.h>
- #include <io.h>
- #include <fcntl.h>
- #include <alloc.h> /* N2 04-05-91 */
- #include "bm.h"
- #include "proto.h" /* N2 04-05-91 */
-
- int GetPatFile(char *PatFile,struct PattDesc *DescVec[])
- /* --------------
- char *PatFile;
- struct PattDesc *DescVec[];
- ----------------- */
- /* read patterns from a file and set up a pattern descriptor vector */
- {
- /* extern char *malloc(); N2 04-05-91 */
- int PFile;
- struct stat StatBuff;
- int PatSize; /* the number of chars in all the patterns */
- char *PatBuff = NULL; /* hold the patterns */
- int file_size;
-
- if ((PFile = open(PatFile,O_TEXT)) < 0)
- {
- fprintf(stderr,"bm: can't open pattern file %s\n",PatFile);
- exit(2);
- } /* if */
- /* find out how big the patterns are */
- if (fstat(PFile,&StatBuff) == -1)
- {
- fprintf(stderr,"bm: can't fstat %s\n",PatFile);
- exit(2);
- } /* if */
- PatSize = (int)StatBuff.st_size;
- if (!PatSize)
- {
- fprintf(stderr,"bm: pattern file is empty\n");
- exit(2);
- } /* if */
- if (!(PatBuff = (char*)malloc(PatSize))) // 11-28-91
- {
- fprintf(stderr,"bm: insufficient memory to store patterns\n");
- exit(2);
- } /* if */
- file_size = read(PFile,PatBuff,PatSize); /* get the patterns */
- close(PFile);
- /* make sure the patterns are null-terminated. We can't have
- * nulls in the patterns */
- if (PatBuff[file_size-1] == '\n')
- {
- PatBuff[file_size-1] = NULL;
- }
- else
- {
- PatBuff[file_size] = NULL;
- }
- return(MkDescVec(DescVec,PatBuff));
- } /* GetPatFile */
-